<?php
use think\Db;
use taobao\AliSms;
use lib\Smsqq\FileVoiceSender;
use lib\Smsqq\SmsMobileStatusPuller;
use lib\Smsqq\SmsMultiSender;
use lib\Smsqq\SmsSenderUtil;
use lib\Smsqq\SmsSingleSender;
use lib\Smsqq\SmsStatusPuller;
use lib\Smsqq\SmsVoicePromptSender;
use lib\Smsqq\SmsVoiceVerifyCodeSender;
use lib\Smsqq\TtsVoiceSender;
use lib\Smsqq\VoiceFileUploader;
/**
 * 调用系统的API接口方法（静态方法）
 * api('User/getName','id=5'); 调用公共模块的User接口的getName方法
 * api('Admin/User/getName','id=5');  调用Admin模块的User接口
 * @param  string  $name 格式 [模块名]/接口名/方法名
 * @param  array|string  $vars 参数
 */
function api($name,$vars=array()){
    $array     = explode('/',$name);
    $method    = array_pop($array);
    $classname = array_pop($array);
    $module    = $array? array_pop($array) : 'common';
    $callback  = 'app\\'.$module.'\\Api\\'.$classname.'Api::'.$method;
    if(is_string($vars)) {
        parse_str($vars,$vars);
    }
    return call_user_func_array($callback,$vars);
}

/**
 * 获取配置的分组
 * @param string $group 配置分组
 * @return string
 */
function get_config_group($group=0){
    $list = config('config_group_list');
    return $group?$list[$group]:'';
}

/**
 * 获取配置的类型
 * @param string $type 配置类型
 * @return string
 */
function get_config_type($type=0){
    $list = config('config_type_list');  
    return $list[$type];
}


/**
 * 发送短信(参数：签名,模板（数组）,模板ID，手机号)
 */
function sms($signname='',$param=[],$code='',$phone){
    $alisms = new AliSms();
    $result = $alisms->sign($signname)->data($param)->code($code)->send($phone);
    return $result['info'];
}
/**
 * 发送短信 
 * @param	$phone	手机号码
 * @param	$code 	验证码
 */
function sms2($phone){
	$time=time();
	$sms=Db::name('smsLog')->where('phone',$phone)->find();
	if(($sms['exp_time'] + 300) > $time){
		$yu=$sms['exp_time'] + 300 - $time;
		return rel(-1,'距离失效还有'.$yu.'秒',$sms['smscode']);
	}else{
		$appid	 ='1400067288';
		$appkey	 ='1cf3e65bd242986343156b71772059c8';
		$smsSign = "联发科网络";
		$templateId=131695;
		$code=doVerify(4);
		$param=[$code];
		$content="您好，您当前操作的验证码为{1}，请于5分钟内填写。如非本人操作，请忽略本短信。";
		$ssender = new SmsSingleSender($appid, $appkey);
	    $result = $ssender->sendWithParam("86", $phone,$templateId,$param,$smsSign,"","");
	    $rsp = json_decode($result,true);
	    if($rsp['errmsg']=='OK'){
	    	Db::name('smsLog')->insert(['phone'=>$phone,'smscode'=>$code,'exp_time'=>$time]);
	    	return rel(1,'发送成功');
	    }else{
	    	return rel(-1,$rsp['errmsg']);
	    }
	}
}
